package com.yiwei.zhh.fragment;

import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.yiwei.zhh.R;
import com.yiwei.zhh.model.V3HomeIndexModel;
import com.yiwei.zhh.util.DisplayUtil;
import com.yiwei.zhh.util.Spans;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by xsooy-pc on 18-6-12.
 */

public class V3HomeBottomOneFragment extends BaseFragment {
    //    @BindView(R.id.img_icon)
//    CircleImageView imgIcon;
    @BindView(R.id.fl_background)
    FrameLayout flBackground;
    //    @BindView(R.id.cardView)
//    CardView cardView;
    Unbinder unbinder;
    @BindView(R.id.txt_title)
    TextView txtTitle;
    @BindView(R.id.txt_info)
    TextView txtInfo;
    private V3HomeIndexModel.DataBean.DealUserListBean data;
    private int x30;
    private int x24;

    @Override
    protected int setLayoutId() {
        return R.layout.fragment_v3_bottom_one;
    }

    public void setData(V3HomeIndexModel.DataBean.DealUserListBean data) {
        this.data = data;
    }

    @Override
    protected void initView() {
        x30 = getResources().getDimensionPixelSize(R.dimen.x30);
        x24 = getResources().getDimensionPixelSize(R.dimen.x24);
        if (data != null) {
            txtTitle.setText(data.name + "  " + data.sex + "  " + data.ages + "岁");
            txtInfo.setText(data.description);
//            Spanned info = Spans.with(this).font(data.name + "  " + data.sex + "  " + data.ages + "岁", x30).font("\n\n" + data.description, x24).build();
//            txtInfo.setText(info);
//            Glide.with(getContext()).load(data.portrait).into(imgIcon);
            try {
                int colors[] = new int[]{Color.parseColor(data.left_color), Color.parseColor(data.right_color)};
                GradientDrawable g = new GradientDrawable(GradientDrawable.Orientation.TL_BR, colors);
                g.setCornerRadius(DisplayUtil.dip2px(getContext(), 10));
                flBackground.setBackgroundDrawable(g);
            } catch (Exception ex) {

            }
        }

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
